package cn.micai.base.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 描述：Java – How to convert a primitive Array to List
 * <p>
 *     如何将一个原始数组转换成列表
 *
 * @author: 赵新国
 * @date: 2018/6/22 19:39
 */
public class PrimitiveArrayToListExample {

    public static void main(String [] args) {

        int[] number = {1,2,3,4,5,6,7,8,9};

        // 1. Classic Example
        /*List<Integer> list = new ArrayList<>();
        for (int i : number) {
            list.add(i);
        }
        System.out.println(list);*/

        // 2. Java 8 Stream
        List<Integer> list = Arrays.stream(number).boxed().collect(Collectors.toList());
        System.out.println(list);

    }


}
